﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.Chess.CommonLayer
{
    public abstract class StandardMoveFactory : AMoveFactory
    {
        // consider moving all this code into the Piece instantiation and using it as an example of the Factory Method pattern

        public StandardMoveFactory(AChessBoard board)
            : base(board)
        {}

        public override AMove CreatePawnMove()
        {
            return new PawnMove(_board);
        }

        public override AMove CreateKnightMove()
        {
            return new KnightMove(_board);
        }

        public override AMove CreateBishopMove()
        {
            return new BishopMove(_board);
        }

        public override AMove CreateRookMove()
        {
            return new RookMove(_board);
        }

        public override AMove CreateQueenMove()
        {
            return new QueenMove(_board);
        }

        public override AMove CreateKingMove()
        {
            return new KingMove(_board);
        }

        /// <summary>
        /// Provides extensibility to allow a subclassed factory to produce other types of pieces.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public override AMove CreateMove(Type t)
        {
            if (t == typeof(KingMove)) { return CreateKingMove(); }
            else if (t == typeof(QueenMove)) { return CreateQueenMove(); }
            else if (t == typeof(RookMove)) { return CreateRookMove(); }
            else if (t == typeof(BishopMove)) { return CreateBishopMove(); }
            else if (t == typeof(KnightMove)) { return CreateKnightMove(); }
            else if (t == typeof(PawnMove)) { return CreatePawnMove(); }
            else
            {
                //return null;
                throw new InvalidOperationException("This Factory cannot produce the specified Type.");
            }
        }
    }
}
